package com.nike.amoeba.bean.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.nike.amoeba.bean.db.StockManageListBean

/**
 * @Author nike
 * @Date 2023/7/28 10:34
 * @Description
 */
@Dao
interface StockManageListDao {

    /**
     * 增加
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun add(vararg bean: StockManageListBean)

    /**
     * 查一个
     */
    @Query("SELECT * FROM StockManageListBean WHERE warehouseId =:id")
    fun find(id: String): StockManageListBean

    /**
     * 更新
     */
    @Update
    suspend fun update(bean: StockManageListBean)

    //删除数据库表全部数据
    @Query("delete from StockManageListBean")
    suspend fun deleteAll()

    //根据ID删除全部
    @Query("DELETE FROM StockManageListBean WHERE warehouseId = :id")
    suspend fun deleteIdAll(id: String)

    suspend fun insertOrUpdate(bean: StockManageListBean) {
        val find = find(bean.warehouseId!!)
        if (find == null){
            add(bean)
        }else{
            update(bean)
        }
    }

}